/*
	Panel used to allow players to change teams and classes during play.
*/

//Initialize panel table
PANEL = {};

function PANEL:Init()
	
	self:SetTitle("Team Selection Menu");
	//Set initial size
	self:SetSize(350, 350);
	local screenWidth = surface.ScreenWidth();
	local screenHeight = surface.ScreenHeight();
	
	self:SetPos(screenWidth/2-350/2, 100+screenHeight/2-350/2);
	
	//Create inital controls
	
	//Top piece
	local topSide = vgui.Create("DForm");
	topSide:SetName("Team Select");
	
	//Setup team choice
	local t = LocalPlayer():Team();
	local cmbTeam = topSide:MultiChoice( "Team: ", nil);
	cmbTeam:AddChoice("Rebels", 1);
	cmbTeam:AddChoice("Combine", 2);
	self.changeTo = 0;
	
	local this = self;
	function cmbTeam:OnSelect(index, value, data) this.changeTo = data; end
	local but = topSide:Button("Suicide and Change", nil, nil);
	function but:DoClick() this:TeamChanger(this.changeTo); this:Remove(); return; end
	cmbTeam:ChooseOption(cmbTeam:GetOptionText(t), t);
	
	//Setup lower form
	local downSide = vgui.Create("DForm");
	downSide:SetName("Class Select");
	
	local classes = Class:GetClassList();
	
	for key, val in pairs(classes) do
		downSide:Button(val, "changeClass", val);
	end
	
	//Create the divider
	local divider = vgui.Create("DVerticalDivider",self);
	divider:SetSize(350,300);
	divider:SetPos(0, 25);
	divider:SetTop(topSide);
	divider:SetBottom(downSide);
end

function PANEL:TeamChanger(data)
	RunConsoleCommand("changeTeam", data);
end

//Register the control with derma
derma.DefineControl( "DTeamSelect", "Used to allow players to switch teams", PANEL, "DFrame");